<?php

namespace App\Http\Controllers\Frontend\Users;

use Illuminate\Http\Request;
use App\Http\Models\Student\ApiFrom;
use App\Http\Service\frontend\StudentService;
use App\Http\Models\Student\StudentFrontendFrom;
use \App\Http\Controllers\Frontend\ApiController;
use App\Http\Models\Student\StudentFrontendImproveFrom;

class StudentController extends ApiController
{

    private $studentService;

    public function __construct(StudentService $studentService) {
        $this->studentService = $studentService;
    }

    public function index(StudentFrontendFrom $studentFrontendFrom) {
        if ($res = $this->studentService->index($studentFrontendFrom)) {
            return $this->success($res, INSERT_SUCCES);
        }
        return $this->errors(NOT_DATA, INSERT_ERROR);
    }

    public function getUserInfo($openId) {
        $result = $this->studentService->getUserInfo($openId);
        if ($result) {
            return $this->success($result);
        }
        return $this->errors(NOT_DATA, NOT_INFO);
    }

    //我的预约订单
    public function getUserOrder(ApiFrom $apiFrom) {
        return $this->success($this->studentService->getUserOrder($apiFrom));
    }

    //获取openID
    public function getOpenId(Request $request) {
        $result = $this->studentService->getOpenId($request->post());
        if (isset($request['codes'])) {
            $this->errors(NOT_DATA, $result['message']);
        }
        return $this->success($result);
    }

    //完善信息
    public function information(StudentFrontendImproveFrom $studentFrontendImproveFrom) {
        $result = $this->studentService->information($studentFrontendImproveFrom);
        if ($result['code'] === 200) {
            return $this->success(NOT_DATA, $result['message']);
        }
        return $this->errors(NOT_DATA, $result['message']);
    }

}
